#include <iostream>
#include <unordered_map>
#include <cmath>

using namespace std;

unordered_map<string, int> numMapping = {
    {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3},
    {"four", 4}, {"five", 5}, {"six", 6}, {"seven", 7},
    {"eight", 8}, {"nine", 9}
};

bool isPrime(int num) {
    if (num < 2) {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    string word1, word2, word3;
    cin >> word1 >> word2 >> word3;

    int num = numMapping[word1] * 100 + numMapping[word2] * 10 + numMapping[word3];

    if (num < 100 || num > 999) {
        cout << "Wrong input" << endl;
        return 0;
    }

    int lower = num;
    int higher = num;
    while (!isPrime(lower) && !isPrime(higher)) {
        lower--;
        higher++;
    }

    if (isPrime(lower)) {
        cout << lower << endl;
    } else {
        cout << higher << endl;
    }

    return 0;
}
